package com.wangzhixuan.controller;

import com.wangzhixuan.db.bean.*;
import com.wangzhixuan.service.CommentService;
import com.wangzhixuan.service.DepartmentService;
import com.wangzhixuan.service.DoctorService;
import com.wangzhixuan.service.OrderService;
import com.wangzhixuan.vo.JsonVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.List;

@Controller
@RequestMapping("/")
public class CommentController extends BaseController{
    @Autowired
    private CommentService commentService;
    @Autowired
    private OrderService orderService;


    @ResponseBody
    @RequestMapping(value = "/addComment.json", method = RequestMethod.POST)
    public JsonVo<String> addComment(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap,
                                   long orderId, int doctorScore,int serverScore, String memo ) {
        try {
            request.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        Customer currentCustomer = getCurrentCustomer(request);
        Order order=orderService.getOrderById(orderId);
        JsonVo<String> vo=new JsonVo<String>();
        Comment comment=new Comment();
        comment.setOrderId(orderId);
        comment.setCustomerId(currentCustomer.getId());
        comment.setDoctorId(order.getDoctorId());
        comment.setDoctorScore(doctorScore);
        comment.setServerScore(serverScore);
        comment.setComment(memo);
        commentService.addComment(comment);
        vo.setResult(true);
        vo.setT("");
        return vo;
    }
}
